<template>
	<view class="p-10">
		<view class="card">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData"></my-forms>
			<u-button type="primary" shape="circle" text="保存任务" @click="submit"></u-button>
		</view>
	</view>
</template>
<script setup>
	import {
		computed,
		reactive,
		ref
	} from 'vue'
	import {
		addExam
	} from '@/api/exam.js'
	import date from '@/utils/date.js'
	// 校验表单数据
	let formData = computed(() => {
		return [{
			itemType: 'select',
			type: 'GETuseList',
			label: '考核人',
			required: true,
			prop: 'assessorId'
		}, {
			itemType: 'select',
			type: 'GETpostList',
			label: '考核部门类型',
			required: true,
			prop: 'examJob'
		}, {
			itemType: 'cascader',
			type: 'GETdeptTree',
			label: '考核部门',
			required: true,
			prop: 'assessorDeptId'
		}, {
			itemType: 'select',
			label: '被考核人',
			required: true,
			type: 'GETuseList',
			prop: 'examPeopleId'
		}, {
			itemType: 'cascader',
			type: 'GETdeptTree',
			label: '被考核部门',
			required: true,
			prop: 'examDeptId'
		}, {
			itemType: 'date',
			type: 'date',
			label: '考核时间',
			required: true,
			prop: 'examTime'
		}, {
			label: '扣分',
			required: true,
			prop: 'fineScore'
		}, {
			itemType: 'textarea',
			label: '扣分原因',
			prop: 'mainReason'
		}].filter(i => i)
	})
	const valiForm = ref(null)
	const valiFormData = reactive({})
	// 保存提交
	const submit = () => {
		valiForm.value.$refs.refMyForm.validate().then(async (res) => {
			console.log('success', valiFormData);
			const {
				code,
				msg
			} = await addExam(valiFormData)
			if (code == 200) {
				uni.showToast({
					icon: 'success',
					title: `新增成功`
				})
				uni.navigateBack({
					delta: 1 // 返回的页面数，如果是1则返回上一页
				})
			} else {
				uni.showToast({
					title: msg
				})
			}
		}).catch(err => {
			console.log('err', err);
		})
	}
</script>
<style lang="scss" scoped>
</style>